package cn.aws360.boot.extend.open.starter.controller;

import cn.aws360.boot.base.api.pojo.response.ResultModel;
import cn.aws360.boot.extend.open.api.pojo.response.ItemModel;
import cn.aws360.boot.extend.open.biz.service.ChatService;
import cn.aws360.boot.extend.open.biz.service.HotsService;
import cn.aws360.boot.extend.open.biz.service.RecommendService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.aws360.boot.extend.open.api.constant.OpenConstant.*;

/**
 * @author junnan
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/open")
@ApiSupport(order = MODULE_OPEN_CODE)
@Api(value = MODULE_OPEN_NAME, tags = MODULE_OPEN_TAGS)
public class OpenController {

    private final ChatService chatService;
    private final HotsService hotsService;
    private final RecommendService recommendService;

    @GetMapping("/chat/{type}")
    @ApiOperation(value = "在线聊天问答")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParam(name = "type", value = "类别 type", dataTypeClass = String.class, required = true)
    public ResultModel<String> chat(@PathVariable String type, String input) {
        return ResultModel.ok(chatService.getChatRes(type, input));
    }

    @GetMapping("/hot/news/{type}")
    @ApiOperation(value = "获取热点新闻")
    @ApiOperationSupport(order = 2)
    @ApiImplicitParam(name = "type", value = "类别 type", dataTypeClass = String.class, required = true)
    public ResultModel<List<ItemModel>> hotList(@PathVariable String type) {
        return ResultModel.ok(hotsService.getNewsList(type));
    }

    @GetMapping("/rec/news")
    @ApiOperation(value = "获取推荐新闻")
    @ApiOperationSupport(order = 3)
    public ResultModel<ItemModel> recNews() {
        return ResultModel.ok(recommendService.getRecNews());
    }

    @GetMapping("/rec/image")
    @ApiOperation(value = "获取推荐图片")
    @ApiOperationSupport(order = 4)
    public ResultModel<ItemModel> recImage() {
        return ResultModel.ok(recommendService.getRecImage());
    }

    @GetMapping("/rec/music")
    @ApiOperation(value = "获取推荐音乐")
    @ApiOperationSupport(order = 5)
    public ResultModel<List<ItemModel>> recMusic() {
        return ResultModel.ok(recommendService.getRecMusicList());
    }

}
